﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.Serialization;
using WLMCoreLibrary;
using MiWebSite_Core;

namespace MWS_Blog
{
    public partial class xml : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Application["blogXML"] == null)
            {

                WebSiteMainConfiguration config = WebSiteMainConfiguration.GetConfig();
                MWSModuleConfiguration blogConfig = MWSModuleConfiguration.GetConfig("MiWebSiteConfiguration/BlogCofig");
                dbConnector ConexionDB = new dbConnector(config.Connections[0].value);
                MiWebSiteBlogEntryCollection feed = new MiWebSiteBlogEntryCollection(ref ConexionDB);
                ConexionDB.CloseConnection();
                feed.channel.title = config.Settings["siteName"].value;
                feed.channel.languaje = "es";
                feed.channel.link = config.Settings["siteURL"].value;
                Application["blogXML"] = WLMFunctions.SerializeObject(feed, true);
                XmlSerializer ser = new XmlSerializer(feed.GetType());
                System.Text.StringBuilder sb = new System.Text.StringBuilder();

                System.IO.StringWriter writer = new StringWriterWithEncoding(System.Text.Encoding.UTF8);
                ser.Serialize(writer, feed);
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(writer.ToString());
            }
            Response.ContentType = "text/xml";
            Response.Write(Application["blogXML"]);
        }
    }
}